package com.example.ll_video.activity;

import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

import com.example.ll_video.R;
import com.qmuiteam.qmui.widget.QMUIProgressBar;
import com.qmuiteam.qmui.widget.webview.QMUIBridgeWebViewClient;
import com.qmuiteam.qmui.widget.webview.QMUIWebView;
import com.qmuiteam.qmui.widget.webview.QMUIWebViewClient;

import butterknife.BindView;
import butterknife.ButterKnife;

public class WebViewActivity extends BaseActivity {
    @BindView(R.id.progress_horizontal)
    QMUIProgressBar progressHorizontal;
    @BindView(R.id.web_view)
    QMUIWebView webView;

    @Override
    public void onCreate() {
        contentView(R.layout.activity_webview_ll);
        ButterKnife.bind(this);

        showBackImage(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        String url = getIntent().getStringExtra("url");
        webView.setWebViewClient(new QMUIWebViewClient(true, true));
        webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);
                setTitle(title);
            }

            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                if (newProgress == 100) {
                    progressHorizontal.setVisibility(View.GONE);
                } else {
                    if (progressHorizontal.getVisibility() == View.GONE)
                        progressHorizontal.setVisibility(View.VISIBLE);
                    progressHorizontal.setProgress(newProgress);
                }

            }
        });
        webView.loadUrl(url);
    }
}
